package com.ruoyi.system.domain;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.math.MathUtils;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 设计方案批次对象 mstn_scheme_batch
 * 
 * @author ruoyi
 * @date 2024-09-05
 */
@Data
public class MstnSchemeBatch extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键 */
    private Long batchId;

    /** 方案状态 */
    @Excel(name = "方案状态")
    private String schemeStatus;

    /** 项目id */
    @Excel(name = "项目id")
    private Long projectId;

    /** 烟气流向（0 垂直方向 1 水平方向） */
    @Excel(name = "烟气流向", readConverterExp = "0=垂直方向,1=水平方向")
    private String smokeFlow;

    /** 催化剂名称 */
    @Excel(name = "催化剂名称")
    private String catalystsName;

    /** 催化剂类型号 */
    @Excel(name = "催化剂类型号")
    private String categoryName;

    /** 每台机组反应器数 */
    @Excel(name = "每台机组反应器数")
    private Integer reactorCount;

    /** 机组数量 */
    @Excel(name = "机组数量")
    private Integer groupCount;

    /** 催化剂化学寿命 */
    @Excel(name = "催化剂化学寿命")
    private Integer lifetime;

    @Excel(name = "出口Nox含量")
    private BigDecimal outNox;

    @Excel(name = "出口氨逃逸")
    private BigDecimal outNh3;

    /** 项目状态(1=创建项目 2=录入条件 3=催化剂方案生成 4=校核 5=技术方案 6=二次校核 7=生产订单) */
    @Excel(name = "项目状态(1=创建项目 2=录入条件 3=催化剂方案生成 4=校核 5=技术方案 6=二次校核 7=生产订单)")
    private String projectStatus;

    /** 计算结果 */
    private String resultCatalysts;

    /** 录入条件者 */
    @Excel(name = "录入条件者")
    private String keyboarder;

    /** 录入条件时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "录入条件时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date inputTime;

    /** 校核者 */
    @Excel(name = "校核者")
    private String checkBy;

    /** 校核时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "校核时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date checkTime;

    /** 二次校核者 */
    @Excel(name = "二次校核者")
    private String verifyBy;

    /** 二次校核时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "二次校核时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date verifyTime;

    /** 矩阵X */
    private Integer matrixX;
    /** 矩阵Y */
    private Integer matrixY;

    /** 层数 */
    private Integer floors;
    /** 反应器L */
    private Integer reactorL;
    /** 反应器W */
    private Integer reactorW;


    List<MstnSchemeCompute> computeList;
    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("batchId", getBatchId())
            .append("schemeStatus", getSchemeStatus())
            .append("projectId", getProjectId())
            .append("smokeFlow", getSmokeFlow())
            .append("categoryName", getCategoryName())
            .append("reactorCount", getReactorCount())
            .append("lifetime", getLifetime())
            .append("projectStatus", getProjectStatus())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("keyboarder", getKeyboarder())
            .append("inputTime", getInputTime())
            .append("checkBy", getCheckBy())
            .append("checkTime", getCheckTime())
            .append("verifyBy", getVerifyBy())
            .append("verifyTime", getVerifyTime())
            .append("remark", getRemark())
            .toString();
    }

    //别问为啥不起个别名，名字太多 我起不明白了
    public String getContentByIndex(int index, MstnSchemeComputeResult result) {
        switch (index){
            case 0:
                return "数据";
            //催化剂型号
            case 1:
                return result.getCatalystsName() + result.getCategoryName();
            //每台装置催化剂体积
            case 2:
                return result.getCatalystsVolume().toString();
            //反应器数
            case 3:
                return result.getReactorCount().toString();
            //催化剂总体积
            case 4:
                return result.getCatalystTotalVolume().toString();
            // 每台反应器催化剂层数
            case 5:
                return result.getReactorFloor().toString();
            // 催化剂单元阵列
            case 6:
                return result.getUnitMatrixCount();
            //每台反应器每层催化剂单元数量
            case 7:
                return result.getSingleReactorUnitCount().toString();
            //单元型号
            case 8:
                return result.getModuleName();
            //单元尺寸
            case 9:
                return result.getModuleSize();
            //每层催化剂净高
            case 10:
                return result.getCatalystsHeight().toString();
            //反应器尺寸（L×W）
            case 11:
                return result.getReactorSize();
            //每个单元的毛重
            case 12:
                return result.getWeight().toString() + "±" + result.getErrorRate().toString();
            // 每台反应器内单元数量
            case 13:
                return result.getSingleReactorUnitCount().toString();
            default:
                return "";
        }
    }

    public String getResultByIndex(int index, Long catalystsId,List<MstnCatalystsCharts> chartsList, MstnSchemeCompute mstnSchemeCompute, MstnCatalysts mstnCatalysts) {
        Map<String, Object> result = chartsList.stream().filter(item -> item.getCatalystsId().equals(catalystsId)).collect(Collectors.toMap(MstnCatalystsCharts::getChartsType, MstnCatalystsCharts::getYValue));
//        图表类型(1=脱硝效率、2=活性数据、3=SO2氧化铝、4=氨逃逸、5=压力降)
        switch (index){
            case 0:
                return "数据";
            case 1:
                return String.valueOf(getLifetime());
            case 2:
                return String.valueOf(getOutNox());
            case 3:
                return String.valueOf(getOutNh3());
            case 4:
                return MathUtils.nh3Consume(mstnSchemeCompute.getQuantityFlow(), mstnSchemeCompute.getO(), mstnSchemeCompute.getNox(), mstnSchemeCompute.getH2o(), getOutNox()).toString();
            case 5:
                return String.valueOf(result.get("5"));
            case 6:
                return MathUtils.pressure(new BigDecimal(mstnSchemeCompute.getTemperature()),
                                            mstnCatalysts.getRippleH(),
                                            mstnCatalysts.getCatalystsH()
                                            .divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP),
                                            mstnSchemeCompute.getQuantityFlow(),mstnSchemeCompute.getMatrixX(),mstnSchemeCompute.getMatrixY(),
                                            mstnCatalysts.getFrictionalDrag(),
                                            mstnCatalysts.getFmCoefficient()).toString();

            default:
                return "MSCR" + StringUtils.leftPad(String.valueOf(getBatchId()), 6, "0");
        }
    }


}
